CREATE TABLE [forumForums](
	[id] [int] NOT NULL	PRIMARY KEY,
	[latestTopic] [int] NOT NULL DEFAULT (0),
	[latestComment] [int] NOT NULL DEFAULT (0),
	[totalTopics] [int] NOT NULL DEFAULT (0),
	[totalComments] [int] NOT NULL DEFAULT (0),
	[latestAuthor] varchar(50) NOT NULL DEFAULT(''),
	[latestPostDate] [datetime] NOT NULL DEFAULT (getdate()),
	[sortOrder] [int] NOT NULL DEFAULT (0),
	[parentId] [int] NOT NULL
)
GO

CREATE TABLE [forumTopics](
	[id] [int] NOT NULL PRIMARY KEY IDENTITY,
	[parentId] [int] NOT NULL FOREIGN KEY REFERENCES [forumForums] ([id]) ON DELETE CASCADE,
	[memberId] varchar(50) NOT NULL,
	[title] [nvarchar](70) NOT NULL,
	[body] [ntext] NOT NULL,
	[created] [datetime] NOT NULL DEFAULT (getdate()),
	[updated] [datetime] NOT NULL DEFAULT (getdate()),
	[locked] [bit] NOT NULL DEFAULT ((0)),
	[latestReplyAuthor] varchar(50) NOT NULL DEFAULT (''),
	[urlName] [nvarchar](300) NOT NULL,
	[replies] [int] NOT NULL,
)
GO

CREATE TABLE [forumComments](
	[id] [int] NOT NULL PRIMARY KEY IDENTITY,
	[topicId] [int] NOT NULL FOREIGN KEY REFERENCES [forumTopics] ([id]) ON DELETE CASCADE,
	[memberId] varchar(50) NOT NULL,
	[body] [ntext] NOT NULL,
	[created] [datetime] NOT NULL DEFAULT (getdate()),
	[position] [int] NOT NULL
)
GO